﻿using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using DevTrends.MvcDonutCaching;
using ECG.Common;
using ECG.DAL;
using ECG.WebUI.Models;

namespace ECG.WebUI.Controllers
{
    public class PromotionController : Controller
    {
        //
        // GET: /Promotion/
        
        [DonutOutputCache(Duration = 3600, VaryByParam = "page")]
        public ActionResult Index(int page = 1)
        {
            ViewBag.CurrentPage = page;
            return View();
        }

        [DonutOutputCache(Duration = 3600, VaryByParam = "page;categoryId")]
        public ActionResult ProductPromotionByCate(int page = 1, string categoryId = "")
        {
            ViewBag.CurrentPage = page;
            ViewBag.CategoryId = categoryId;
            return View();
        }

        public ActionResult ProductPromotionListByCate(int page, string categoryId)
        {
            int totalPage = 0;
            var itemsPerPage = int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var model = ProductDb.GetAllProductPromotionByCate(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };

            var category = ProductCategoryDb.GetById(categoryId) ?? new ProductCategoryDto();
            ViewBag.CategoryId = categoryId;
            ViewBag.CateName = category.Name;
            return PartialView(model);
        }

        public ActionResult ProductPromotionList(int page)
        {
            int totalPage = 0;
            var itemsPerPage = int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var model = ProductDb.GetAllProductPromotion(page, itemsPerPage, ref totalPage) ?? new List<ProductByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            return PartialView(model);
        }

        public ActionResult MenuPromotion(string action, string controller)
        {
            var model = ProductCategoryDb.GetAll() ?? new List<ProductCategoryDto>();
            ViewBag.CatePromotionList = ProductCategoryDb.GetAllCateHasPromotion() ?? new List<ProductCategoryDto>();
            ViewBag.Action = action;
            ViewBag.Controler = controller;
            return PartialView(model);
        }

        /// <summary>
        /// Hien thi thong tin html cua CT khuyen mai dac biet
        /// </summary>
        /// <returns></returns>
        public ActionResult PromotionHtml()
        {
            return View();
        }

    }
}
